home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7938 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: menkar.cs.utk.edu!doolin
  2. From: doolin@menkar.cs.utk.edu (David Doolin)
  3. Newsgroups: comp.lang.c
  4. Subject: why empty dlist?
  5. Date: 29 Feb 1996 20:13:21 GMT
  6. Organization: University of Tennessee Computer Science
  7. Distribution: world
  8. Message-ID: <4h51d1INNcrr@CS.UTK.EDU>
  9. Reply-To: doolin@cs.utk.edu
  10. NNTP-Posting-Host: menkar.cs.utk.edu
  11.  
  12. Why might the following piece of code not work?
  13.  
  14. 1  for (tmp = bedlist->flink; tmp != bedlist->blink; tmp = tmp->flink) {
  15. 2        headl = (Dlist) tmp->val;
  16. 3        headr = (Dlist) tmp->flink->val;
  17.  
  18. Defs: Dlist points forward (flink), backwards (blink),
  19. and types void *val.   tmp, bedlist, headl, and headr are
  20. all Dlist structures.  bedlist consists of a doubly linked
  21. list where every node points to an identical doubly
  22. linked list, which points to some data.  There is a head
  23. node on each list, with null value.
  24.  
  25. bedlist_head<->Node1<->Node2<->...<->Node_last<->bedlist_head
  26.                 ^       ^             ^
  27.                 |       |             |
  28.               headl   headr          etc.   
  29.                 |       |     
  30.               node1   node1
  31.                 |       |    <- these are doubly linked.
  32.                ...     ...
  33.                 |       |
  34.               last    last
  35.  
  36. The object is to construct a new list with combining Node1
  37. list with Node2 list.  The merge proceeds nicely with the 
  38. first loop, and the headr list increments as planned right
  39. down the bedlist, but the headl  doesn't make it past the
  40. first loop.  It merges on the first loop, then remains 
  41. empty through the rest of it.  Doesn't seg fault either.
  42. On the 2d loop, 
  43. I know headl is empty after the assignment on line 2 because 
  44. I checked it; it points to itself, i.e. empty.
  45.  
  46. Am I missing something obvious here?
  47.  
  48. Many thanks for any help,
  49. Dave Doolin
  50.  
  51.  
  52.